# Maintainer: Yassine Oudjana (Tooniis) <y.oudjana@protonmail.com>
# Kernel config based on: arch/arm64/configs/defconfig

_flavor="postmarketos-mediatek-mt6735"
pkgname=linux-$_flavor
pkgver=6.1.9
pkgrel=2
pkgdesc="Linux kernel with patches for devices with the MediaTek MT6735 SoC"
arch="aarch64"
_carch="arm64"
url="https://gitlab.com/mt6735-mainline/linux"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-zram
"
makedepends="bash bison findutils flex installkernel openssl-dev perl"

# Source
_tag=v${pkgver//_/-}-mt6735
source="
	linux-$_tag.tar.gz::$url/-/archive/$_tag/linux-$_tag.tar.gz
	config-$_flavor.$arch
"
builddir="$srcdir/linux-$_tag"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION=$((pkgrel + 1 )) V=1
}

package() {
	mkdir -p "$pkgdir"/boot
	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	install -D "$builddir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
}
sha512sums="
34bf27d0934cd6962a8e84cb79d59fe7b5cc7aed62eee0b2150d0dd77c4fa5a1ad803674bb61192feca99d1ad2e61a1c7d2579f03657fe978dd41d550c84a410  linux-v6.1.9-mt6735.tar.gz
2f2572a92866334149033204e4bd9211fb1b0793731b89f295223c1d9dd518a1756a7071b0d1aac56ea2ded5a09216267fa2f2bfe01f275f5960db80ab2c84a3  config-postmarketos-mediatek-mt6735.aarch64
"
